//
//  LoginViewController.swift
//  驻外机组
//
//  Created by 苏伟 on 16/4/5.
//  Copyright © 2016年 com.csair. All rights reserved.
//

import UIKit
import RealmSwift
    
    
class LoginViewController: UIViewController {
        
        @IBOutlet weak var usernameTextField: UITextField!
        @IBOutlet weak var passwordTextField: UITextField!
        @IBAction func loginBtn(sender: AnyObject) {
            let loginfonew = loginInfo()
            loginfonew.username = "username"
            loginfonew.tokens = "tokens"
            try! uiRealm.write { uiRealm.add(loginfonew)   }
            self.dismissViewControllerAnimated(true, completion: nil)
            
            //        let stb:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            //        let loginview:MainViewController = stb.instantiateViewControllerWithIdentifier("mainviewcontroller") as! MainViewController
            //        self.presentViewController(loginview, animated: true,completion: nil)
        }
        
        //禁止横屏
        override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
            return UIInterfaceOrientationMask.Portrait
        }
        
        override func viewDidLoad() {
            super.viewDidLoad()
            
            // Do any additional setup after loading the view, typically from a nib.
            
            //        let imageView = UIImageView(image: UIImage(named: "CB"))
            //        imageView.frame = UIScreen.mainScreen().bounds
            //        self.view.addSubview(imageView)
            
            
            NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("dealDto:"), name: "DtoinMainThread", object:nil)
            
        }
        deinit {
            //删除事件监听
            NSNotificationCenter.defaultCenter().removeObserver(self)
        }
        
        
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
        
        func dealDto(notification:NSNotification)
        {
            //        let userinfo = notification.userInfo as![String:AnyObject]
            //        let mydto = userinfo["value"] as! Dto
            //        switch mydto.dtotype
            //        {
            //        case DtoType.EmptyDtoType:
            //            "空dto类型"
            //        case DtoType.LoginSuccess:
            //            let stb:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            //            let tdl:MainViewController = stb.instantiateViewControllerWithIdentifier("mainviewcontroller") as! MainViewController
            //            presentViewController(tdl, animated: true,completion: nil)
            //        default:
            //            "未定义的类型"
            //        }
            //        
            //        print(mydto.dtotype)
            
        }
        
        
    }
    

    
    
 